<template>
  <div class="conMain" >
    <el-card  class="box-card" >
      <div slot="header" class="topfix">
          <el-form v-show="box" :inline="true"  ref="searchForm" :model="params" size="small" class="goodsForm"  label-width="100px">
              <el-form-item label="管理员" prop="s_username">
                  <el-input v-model="params.s_username"  placeholder="请输入管理员" />
              </el-form-item>
              <el-form-item label="标题"  prop="s_title">
                  <el-input v-model="params.s_title"  placeholder="请输入标题" />
              </el-form-item>
              <el-form-item label="IP"  prop="s_ip">
                  <el-input v-model="params.s_ip"  placeholder="请输入IP" />
              </el-form-item>
              <el-form-item label="操作时间"  prop="s_createtime">
                  <el-date-picker
                      v-model="params.s_createtime"
                      type="daterange"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                  />
              </el-form-item>
              <el-form-item label=" ">
              <el-button type="primary"  size="small" class="searchBtn" @click="handleSearch" icon='el-icon-search'>搜索</el-button>
              <el-button type="info"  @click="handleRet">重置</el-button>
              </el-form-item>
          </el-form>
          <div style="margin-top: 10px;">
            <el-button v-has="'auth/adminlog/del'"  :disabled="delids?false:true" icon="el-icon-delete" type="danger" size="mini" class="addBtn" @click="del(0)">批量删除</el-button>
            <el-button  style="float: right;" icon="el-icon-search" title="搜索" type="info" plain size="mini"  @click="changebox"></el-button>
          </div>
      </div>
        <el-table  ref="multipleTable"  @selection-change="handleSelectionChange"  v-loading="loading"  :data="list" style="width: 100%;margin-bottom: 20px;" :empty-text='emtypetxt' >
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
            <el-table-column prop="id" label="ID" align="center" width="100" />
            <el-table-column prop="username" label="管理员" align="center"  width="200"/>
            <el-table-column prop="title" label="标题" align="center" />
            <el-table-column prop="ip" label="IP" align="center" />
            <el-table-column prop="useragent" label="Browser" align="center" width="320"/>
            <el-table-column prop="createtime" label="操作时间" align="center"  />
            <el-table-column label="操作" align="center" >
              <template slot-scope="scope">
                  <el-button type="primary" v-has="'auth/adminlog/detail'" size="mini" icon="el-icon-tickets" title='日志详情' plain   @click="detail(scope.row.id)"></el-button>
                  <el-button type="danger" v-has="'auth/adminlog/del'" size="mini" icon="el-icon-delete" title='删除' plain @click="del(scope.row.id)"></el-button>
              </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
              :current-page="params.page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="params.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
        </div>
    </el-card>
    <el-dialog title="日志详情"
    :visible.sync="dialogVisible"
    center  width="30%">
    <div  class="dlog">
      <el-row >
        <el-col :span="12"><div class="grid-content bg-purple">id：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.id}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">管理员ID：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.admin_id}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">管理员：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.username}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">标题：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.title}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">路径：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.url}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">内容：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.content}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">IP：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.ip}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">Browser：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.useragent}}</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"><div class="grid-content bg-purple">操作时间：</div></el-col>
        <el-col :span="12"><div class="grid-content bg-purple-light">{{row.createtime}}</div></el-col>
      </el-row>
    </div>
    </el-dialog>
  </div>
</template>

<script>

import { adminlog_index,adminlog_detail,adminlog_del } from '@/api/auth'

export default {
  data() {
    return {
      dialogVisible: false,
      total:0,
      loading:true,
      emtypetxt:'',
      list: [],
      box:true,
      params: {
        s_username:'',
        s_title:'',
        s_ip:'',
        s_createtime:[],
        page: 1,
        pagesize:10,
        ss_title:'like',
        ss_createtime:'BETWEEN',
      },
      delids:'',
      row:[],
    }
  },
  created() {
    this.adminloglist()
  },
  methods: {
    adminloglist() {
      this.list=[];
      this.emtypetxt='加载中...';
      this.loading=true;
      adminlog_index(this.params).then(res => {
        this.list=res.data.list
        this.total=res.data.total
        this.loading = false
        if(this.list.length==0){
          this.emtypetxt='暂无数据'
        }
      })
    },
    handleRet(){
      this.resetForm('searchForm');
      this.params.page=1
      this.adminloglist()
    },
    handleSearch(){
      this.list=[];
      this.params.page=1;
      this.adminloglist()
    },
    //分页
    handleSizeChange(val) {
        this.params.pagesize = val
        this.adminloglist()
    },
    handleCurrentChange(val) {
        this.params.page = val
        this.adminloglist()
    },
    changebox(){
      this.box=!this.box;
    },
    //重置表单
    resetForm(formName)
    {
       if (this.$refs[formName]!==undefined) {
          this.$refs[formName].resetFields();
       }
    },
    //批量选择
    handleSelectionChange(val) {
        var str='';
        for (var i = 0; i < val.length; i++) {
      	  str += val[i]['id']+ ",";
      	}
        this.delids = str;
    },
    //查看
    detail(id){
      adminlog_detail({id:id}).then(res => {
          if(res.code==1){
              this.row=res.data.row
              this.dialogVisible=true;
          }
      })
    },
    // 取消
    handleCalcel() {
      this.dialogVisible = false
    },
    del(ids){
      let _this=this;
      _this.$modalSure().then(() => {
         if(ids==0){
             if(_this.delids){
               ids=_this.delids;
             }else{
               _this.$message.error(res.msg);
               return;
             }
         }
         adminlog_del({ids:ids}).then(res => {
             _this.delids='';
             _this.$message.success(res.msg);
             _this.adminloglist()
         })
      })
    }
  },
}
</script>



<style lang="scss" scoped>
  .dlog{
    max-height: 80vh;
    padding:20px 15px 30px 0px;
    overflow: auto;
    .el-row{
      margin-top: 16px;
      font-size: 15px;
    }
  }
</style>
